package com.newland.mesdk.demo.adapter;

import java.util.List;

import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.newland.mesdk.demo.main.R;
import com.newland.mesdk.demo.device.BlueToothDeviceContext;

/**
 * 蓝牙搜索列表适配器
 * 
 * @ClassName BlueToothAdapter
 */
public class BlueToothAdapter extends BaseAdapter {
	private Context context;
	private int optionsGravity = Gravity.CENTER;
	private int xof = 0;
	private int yof = 0;
	private List<BlueToothDeviceContext> blueToothEntities;

	public BlueToothAdapter(Context context, List<BlueToothDeviceContext> blueToothEntities) {
		this(context, blueToothEntities, Gravity.CENTER, 0, 0);
	}

	public BlueToothAdapter(Context context, List<BlueToothDeviceContext> blueToothEntities, int optionsGravity, int xof, int yof) {
		this.context = context;
		this.blueToothEntities = blueToothEntities;
		this.optionsGravity = optionsGravity;
		this.xof = xof;
		this.yof = yof;
	}

	@Override
	public int getCount() {
		return blueToothEntities.size();
	}

	@Override
	public Object getItem(int position) {
		return blueToothEntities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout ll = new LinearLayout(context);
		TextView tv = new TextView(context);
		LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		params.topMargin = 10;
		params.bottomMargin = 10;
		ll.addView(tv, params);
		tv.setGravity(optionsGravity);
		tv.setPadding(xof, yof, 0, 0);
		tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
		tv.setTextColor(context.getResources().getColor(R.color.text_color));
		tv.setText(blueToothEntities.get(position).getName());
		return ll;
	}

}
